<template>
  <el-dialog
      title="打印"
      width="480px"
      @close="cancel"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form v-loading="isLoading">
      <row-col>
        <el-form-item label="单号"/>
        <div v-for="item in numberList" :key="item">{{item}}</div>
        <!-- 大单 -->
        <el-button slot="r" class="float-right mb-15" type="success" @click="printMother()">打印 100 * 180</el-button>
        <!-- 联单 -->
        <el-button slot="r" class="float-right mb-15" type="success" @click="printUnion()">打印 76 * 130</el-button>
        <!-- 汇富通 -->
        <!--<el-button v-if="$special || $level===1" slot="r" class="float-right" type="success" @click="printFu()">打印 汇 富 通</el-button>-->
      </row-col>
    </el-form>

    <div v-show="$isDev">
      <!--母单-->
      <div ref="PrintMother">
        <mother v-for="item in formData" :key="item.number" :item="item"/>
      </div>

      <!--联单-->
      <div ref="PrintUnion">
        <union v-for="item in formData" :key="item.number" :item="item"/>
      </div>

      <!--汇富通-->
      <!--<div ref="PrintFu">-->
      <!--  <fu v-for="item in formData" :key="item.number" :item="item"/>-->
      <!--</div>-->
    </div>

    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">完 成</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {getPrintApi} from '@/api/print'
  import {resetData} from "@/utils/common";
  import Mother from '../components/Mother'
  import Union from '../components/Union'
  // import Fu from '../components/Fu'

  export default {
    name: 'PrintMore',
    components: {Mother, Union},
    data() {
      return {
        visible: false,
        isLoading: false,
        numberList: '',
        formData: []
      }
    },
    methods: {
      printMother() { // 打印母单
        this.$nextTick(() => {
          this.$print(this.$refs['PrintMother'])
        })
      },
      printUnion() { // 打印联单
        this.$nextTick(() => {
          this.$print(this.$refs['PrintUnion'])
        })
      },
      printFu() { // 打印汇富通
        this.$nextTick(() => {
          this.$print(this.$refs['PrintFu'])
        })
      },
      // 获取打印信息
      getPrint() {
        this.isLoading = true
        let param = {}
        param.numbers = this.numberList.join(',')
        getPrintApi(param)
          .then(result => {
            this.formData = result.resultParam.expressOrderDtoList;
            this.$nextTick(() => {
              this.isLoading = false
            })
          })
          .catch(() => {
            this.isLoading = false
          })
      },
      cancel() {
        resetData(this)
      }
    }
  }
</script>
